package com.seven.alert.condition;

import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * @Author seven
 * @Date 2021/1/21 14:54
 * @Description
 * @Version 1.0
 */
@Log4j2
public class MailCondition implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        String host = conditionContext.getEnvironment().getProperty("alert.mail.host");
        String username = conditionContext.getEnvironment().getProperty("alert.mail.username");
        String password = conditionContext.getEnvironment().getProperty("alert.mail.password");
        String form = conditionContext.getEnvironment().getProperty("alert.mail.form");
        log.info("是否开启邮件通知服务：" + (!StringUtils.isEmpty(host) &
                !StringUtils.isEmpty(username) &
                !StringUtils.isEmpty(password) &
                !StringUtils.isEmpty(form)));
        return !StringUtils.isEmpty(host) &
                !StringUtils.isEmpty(username) &
                !StringUtils.isEmpty(password) &
                !StringUtils.isEmpty(form)
                ;
    }
}
